def generate_pascal_triangle(n):
    triangle = []

    for row in range(n):
        # 创建当前行，并初始化为全1
        current_row = [1] * (row + 1)

        # 计算中间的值（除了第一个和最后一个）
        for j in range(1, row):
            current_row[j] = triangle[row - 1][j - 1] + triangle[row - 1][j]

        triangle.append(current_row)

    return triangle


def print_pascal_triangle(triangle):
    max_width = len('   '.join(map(str, triangle[-1])))  # 最后一行宽度用于居中对齐

    for row in triangle:
        row_str = '   '.join(map(str, row))
        print(row_str.center(max_width))


# 主程序入口
if __name__ == '__main__':
    try:
        n = int(input("请输入要打印的杨辉三角的行数 n："))
        if n <= 0:
            print("请输入一个正整数。")
        else:
            pascal_triangle = generate_pascal_triangle(n)
            print_pascal_triangle(pascal_triangle)
    except ValueError:
        print("输入无效，请输入一个整数。")